package gamagora.game.entity
{
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	
	import gamagora.game.resources.OSImages;

	public class OSMovingBox extends OSBox
	{
		private static const WIDTH:Number = 80.0;
		private static const HEIGHT:Number = 80.0;
		
		private var _vel:b2Vec2;
		
		public function OSMovingBox(X:Number = 0, Y:Number = 0, showDebugBox:Boolean = false)
		{
			super(MOVING_BOX, X, Y, WIDTH, HEIGHT, WIDTH, HEIGHT, OSImages.BOX, showDebugBox);
			offset.y = -1;
			_bodyDef.type = b2Body.b2_dynamicBody;
			_bodyDef.fixedRotation = false;
			//_bodyDef.linearDamping = 10.0;
			_fixDef.density = 1.0;
			_fixDef.friction = 0;
			_fixDef.restitution = 0;
		}
		
		public override function update():void
		{
			super.update();
			
			_vel = _body.GetLinearVelocity();
			
			if(_vel.x < 0)
			{
				_vel.x += 0.05;
				if(_vel.x > 0)
				{
					_vel.x = 0;
				}
			}
			else if(_vel.x > 0)
			{
				_vel.x -= 0.05;
				if(_vel.x < 0)
				{
					_vel.x = 0;
				}
			}
		}
	}
}